/**
 * 
 */
package com.gragra.wilsHandler;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import com.gragra.sampling.sequentialStructure.ExtensionLevels;
import com.gragra.sampling.sequentialStructure.WordAndTagHolder;
import com.gragra.sequentiaDataGenerator.BaseGenerator;
import com.gragra.sequentiaDataGenerator.EmptySegmentation;
import com.gragra.util.StringToInt;
/**
 * @author Christoph Teichmann
 * 25.09.2013
 */
public class TransferTags
{
	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException
	{
		BufferedReader from = new BufferedReader(new FileReader(args[0]));
		BaseGenerator bg = new BaseGenerator(new EmptySegmentation());
		Map<String, String> m = new HashMap<String, String>();
		String line;
		while((line = from.readLine()) != null)
		{
			WordAndTagHolder wth = bg.transferSingle(line);
			for(int i=0;i<wth.getLength();++i)
			{m.put(StringToInt.reverse(wth.getWord(i)).toLowerCase(), Integer.toString(wth.getExtensionInformation().getInfiniteInformation(i, ExtensionLevels.ContextTagLevel)));}
		}
		from.close();
		for(int i=1;i<args.length;i+=2)
		{
			from = new BufferedReader(new FileReader(args[i]));
			BufferedWriter to = new BufferedWriter(new FileWriter(args[i+1]));
			boolean first = true;
			while((line = from.readLine()) != null)
			{
				if(first)
				{first = false;}
				else
				{to.newLine();}
				String[] parts = line.split("\\s+");
				for(int j = 0; j < parts.length; ++j)
				{
					if(j!=0)
					{to.write(" ");}
					String string = parts[j];
					String word = string.split("\\|")[0];
					to.write(string+"|"+ExtensionLevels.ContextTagLevel.toString()+"|"+m.get(word.toLowerCase()));
				}
			}
			to.close();
			from.close();
		}
	}
}